USE [FastDeal]
GO
/****** Object:  Table [dbo].[DEAL]    Script Date: 11/10/2013 23:59:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[DEAL](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
	[name] [nvarchar](250) NULL,
	[desc] [nvarchar](max) NULL,
	[dealdate] [datetime] NULL,
	[expired] [datetime] NULL,
	[price] [money] NULL,
	[currency] [varchar](10) NULL,
	[userid] [varchar](50) NULL,
 CONSTRAINT [PK_DEAL] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[COMMENT]    Script Date: 11/10/2013 23:59:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[COMMENT](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
	[desc] [nvarchar](max) NULL,
	[dealid] [bigint] NULL,
	[userid] [varchar](50) NULL,
 CONSTRAINT [PK_COMMENT] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[USER]    Script Date: 11/10/2013 23:59:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[USER](
	[id] [varchar](50) NOT NULL,
	[pass] [varchar](50) NULL,
	[salt] [varchar](50) NULL,
	[fullname] [nvarchar](250) NULL,
	[phone] [varchar](50) NULL,
	[email] [varchar](50) NULL,
	[address] [nvarchar](250) NULL,
	[role] [tinyint] NULL,
	[created] [datetime] NULL,
	[isactive] [bit] NULL,
 CONSTRAINT [PK_USER] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  StoredProcedure [dbo].[Sys_User_Update]    Script Date: 11/10/2013 23:59:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Sys_User_Update]
	@id VARCHAR(50),
		--@pass VARCHAR(50),
		--@salt VARCHAR(50),
		@fullname NVARCHAR(250),
		@phone varchar(50),
		@email varchar(50),
		@address NVARCHAR(250),
		@role TINYINT,
		@created DATETIME
		--@isactive bit
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    UPDATE [USER]
    SET
    	--pass = @pass,
    	--salt = @salt,
    	fullname = @fullname,
    	phone = @phone,
    	email = @email,
    	[address] = @address,
    	[role] = @role,
    	created  =@created
    	 
    WHERE id = @id
END
GO
/****** Object:  StoredProcedure [dbo].[Sys_User_Sel]    Script Date: 11/10/2013 23:59:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Sys_User_Sel]
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    SELECT * FROM [USER] u
    WHERE isactive = 1
END
GO
/****** Object:  StoredProcedure [dbo].[Sys_User_Insert]    Script Date: 11/10/2013 23:59:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Sys_User_Insert] 
	@id VARCHAR(50),
		@pass VARCHAR(50),
		@salt VARCHAR(50),
		@fullname NVARCHAR(250),
		@phone varchar(50),
		@email varchar(50),
		@address NVARCHAR(250),
		@role TINYINT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO [USER]
	(
		id,
		pass,
		salt,
		fullname,
		phone,
		email,
		[address],
		[role]
	)
	VALUES
	(
		@id,
		@pass,
		@salt,
		@fullname,
		@phone,
		@email,
		@address,
		@role
	)
END
GO
/****** Object:  StoredProcedure [dbo].[Sys_User_ChangePass]    Script Date: 11/10/2013 23:59:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Sys_User_ChangePass]
	@id VARCHAR(50),
		@pass VARCHAR(50)
		--@isactive bit
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    UPDATE [USER]
    SET
    	pass = @pass    	
    	 
    WHERE id = @id
END
GO
/****** Object:  StoredProcedure [dbo].[Sys_User_Active]    Script Date: 11/10/2013 23:59:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Sys_User_Active]
	@id VARCHAR(50),
		@isactive bit
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    UPDATE [USER]
    SET
    	isactive = @isactive 
    WHERE id = @id
END
GO
